# -*- coding:utf-8 -*-
__author__ = u'sangbowei'

import time
from urlTestDemo.shipDB import *
from urlTestDemo.visaDB import *
from urlTestDemo.emailUtils import *
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()

allProblemUrlList = [] # 存放所有问题url,可能超时，可能返回404

def testOutbuUrl():
    allVisaProblemUrlList = batchTestVisaUrl()  # 存放签证 问题url
    allShipProblemUrlList = batchTestShipUrl()  # 存放邮轮 问题url
    init_problem_url_list(allVisaProblemUrlList,allShipProblemUrlList)
    base_send_email()

# 开启日常测试任务，daily task, every day 8:00 start execute
# 表示每隔3天17时19分07秒执行一次任务
# sched.add_job(my_job, 'interval',days  = 03,hours = 17,minutes = 19,seconds = 07)
def start_daily_test_job():
    # sched.add_job(testOutbuUrl, 'interval', hours=10)
    return

# delete daily task
def delete_daily_test_job():
    print('delete daily test job')
    sched.remove_job("test_task_job")

# pause daily task
def pause_daily_test_job():
    print('pause daily test job')
    sched.job.Job.pause()
    sched.schedulers.base.BaseScheduler.pause_job()

# resume daily task
def resume_daily_test_job():
    print('resume daily test job')
    sched.job.Job.resume()
    sched.schedulers.base.BaseScheduler.resume_job()

@sched.scheduled_job('interval', seconds=1,id='test_task_job')
def test_task_job():
    print("定时任务测试",time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))


def taskAllJobFunc():
    print('start daily test job')
    sched.start()
    time.sleep(5)
    pause_daily_test_job()
    time.sleep(5)
    resume_daily_test_job()
    time.sleep(5)
    delete_daily_test_job()


taskAllJobFunc()